﻿/*****************************************************************************
 
 Use of Ext is under the Ext JS license, for more information, 
 please visit http://extjs.com/products/license.php page. 
  
 You should confirm that you have read, understood and accept ethical criteria listed. 
 If not, see <http://www.mvcnext.com/license/>.
  
 Version: 1.0.0.0
 Website: http://www.mvcnext.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Reflection;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace MVCnExt.Web.UI.Ext
{

    /// <summary>
    /// Provides editor functionality for inline tree node editing. Any valid Ext.form.Field can be used as the editor field.
    /// </summary>
    [Description("Provides editor functionality for inline tree node editing. Any valid Ext.form.Field can be used as the editor field.")]
    public class ExtTreeEditor : ExtComponent
    {
        ScriptControlDescriptorBase desc;

        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {
            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            if (list.Count == 0)
                list.Add(new ExtScriptControlDescriptor("Ext.tree.TreeEditor", "ctl00"));

            desc = (ScriptControlDescriptorBase)list[0];            

            desc.Type = "Ext.tree.TreeEditor";
            desc.Overloaded = true;

            Type component = typeof(ExtTreeEditor); 

            var propertyList = from property in component.GetProperties()
                               where property.DeclaringType == component
                               select property;

            propertyList.ToList().ForEach(AddProperty);

            if (!String.IsNullOrEmpty(targetID))
            {
                if (String.Compare(targetID, GetControlID(targetID), true) == 0)
                    desc.AddPropertyBase("targetID", String.Format("Ext.getCmp('{0}')", targetID));
                else
                    desc.AddPropertyBase("targetID", String.Format("{0}", GetControlID(targetID)));
            }

            return list;
        }

        #region Public Properties

        /// <summary>
        /// True to cancel the edit when the escape key is pressed (defaults to false)
        /// </summary>
        [Description("True to cancel the edit when the escape key is pressed (defaults to false)")]
        public Boolean? cancelOnEsc { get; set; }

        /// <summary>
        /// tree ID to edit
        /// </summary>
        [Description("tree panel ID to edit.")]
        public String targetID { get; set; }

        /// <summary>
        /// The position to align to (see Ext.Element.alignTo for more details, defaults to "l-l").
        /// </summary>
        [Description("The position to align to (see Ext.Element.alignTo for more details, defaults to l-l).")]
        public String alignment { get; set; }

        /// <summary>
        /// True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only, or "height" to adopt the height only (defaults to false) 
        /// </summary>
        [Description("True for the editor to automatically adopt the size of the underlying field, width to adopt the width only, or height to adopt the height only (defaults to false) ")]
        public Boolean? autosize { get; set; }


        /// <summary>
        /// True to complete the edit when the enter key is pressed (defaults to false) 
        /// </summary>
        [Description("True to complete the edit when the enter key is pressed (defaults to false) ")]
        public Boolean? completeOnEnter { get; set; }

        /// <summary>
        /// True to constrain the editor to the viewport 
        /// </summary>
        [Description("True to constrain the editor to the viewport ")]
        public Boolean? constrain { get; set; }

        /// <summary>
        /// CSS class added to the component when it is disabled (defaults to "x-item-disabled"). 
        /// </summary>
        [Description("CSS class added to the component when it is disabled (defaults to x-item-disabled). ")]
        public String disableClass { get; set; } 

        /// <summary>
        /// True to hide the bound element while the editor is displayed (defaults to false) 
        /// </summary>
        [Description("True to hide the bound element while the editor is displayed (defaults to false) ")]
        public Boolean? hideEl { get; set; } 

        /// <summary>
        /// True to skip the the edit completion process (no save, no events fired) if the user completes an edit and 
        /// the value has not changed (defaults to false). Applies only to string values - edits for other data types will never be ignored.
        /// </summary>
        [Description("True to skip the the edit completion process (no save, no events fired) if the user completes an edit and the value has not changed (defaults to false). Applies only to string values - edits for other data types will never be ignored.")]
        public Boolean? ignoreNoChange { get; set; } 

        /// <summary>
        /// True to shim the editor if selects/iframes could be displayed beneath it (defaults to false) 
        /// </summary>
        [Description("True to shim the editor if selects/iframes could be displayed beneath it (defaults to false) ")]
        public Boolean? shim { get; set; } 

        #endregion
    }
}
